<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">


    <ui:composition template="../../master.xhtml">

        <ui:define name="menu">
            <ui:include src="../menu.xhtml" /> 
        </ui:define>


        <ui:define name="TituloModulo">

            Gestão de Utilizadores
        </ui:define>


        <ui:define name="TituloConteudoPrincipal">
            Pesquisar Utilizador
        </ui:define>


        <ui:define name="ConteudoPrincipal">

            <h:form>  
                <h:panelGrid columns="2">
                    <p:ajaxStatus  style="display: inline" >
                        <f:facet name="start">
                            <p:graphicImage alt="carregando!!" url="/resources/ajaxloading.gif"/>
                        </f:facet>
                        <f:facet name="default">
                            <h:outputText styleClass="ui-icon ui-icon-bullet"/>
                        </f:facet>
                        <f:facet name="complete">
                            <h:outputText styleClass="ui-icon ui-icon-check"/>
                        </f:facet>                 
                    </p:ajaxStatus>

                    <p:outputPanel>
                        <h:outputLabel for="nome" value="Insira o nome do Usuario" style="display: inline"/>
                        &nbsp;
                        <p:inputText id="nome" required="true" style="display: inline" value="#{loginUsuarioController.nome}" requiredMessage="#{bundle01.obrigatorio}">
                            <p:ajax  update="painel" event="keyup" listener="#{loginUsuarioController.actualizarItemsPesquisa}"/>
                        </p:inputText>
                        &nbsp;
                        <p:commandButton value="Procurar" style="display: inline" update="painel" actionListener="#{loginUsuarioController.actualizarItemsPesquisa}"/>

                    </p:outputPanel>
                </h:panelGrid>

                <p:messages globalOnly="true"/>
                <p:outputPanel id="painel" >
                    <p:panel header="Sem correspondência" closable="true" rendered="#{loginUsuarioController.items.rowCount == 0}"/>


                    <p:panel  header="Utilizadores" closable="false" style="border: 0px" rendered="#{loginUsuarioController.items.rowCount > 0}" toggleSpeed="2000" >


                        <h:outputText value="#{loginUsuarioController.pagination.pageFirstItem + 1}..#{loginUsuarioController.pagination.pageLastItem + 1}/#{loginUsuarioController.pagination.itemsCount}"/>&nbsp;
                        <p:commandLink update="tabela" actionListener="#{loginUsuarioController.previous}" value="#{bundle01.anterior} #{loginUsuarioController.pagination.pageSize}" rendered="#{loginUsuarioController.pagination.hasPreviousPage}"/>&nbsp;
                        <p:commandLink update="tabela" actionListener="#{loginUsuarioController.next}" value="#{bundle01.posterior} #{loginUsuarioController.pagination.pageSize}" rendered="#{loginUsuarioController.pagination.hasNextPage}"/>&nbsp;
                        <p:dataTable id="tabela" value="#{loginUsuarioController.items}" var="item" >

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="#{bundle01.nomeUsuario}"/>
                                </f:facet>
                                <h:outputText value="#{item.nomeUsuario}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="#{bundle01.tipoUsuario}"/>
                                </f:facet>
                                <h:outputText value="#{item.fkTipoUsuario.designacao}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="#{bundle01.cadastrador}"/>
                                </f:facet>
                                <h:outputText value="#{item.fkLoginCadastrador.nomeUsuario}"/>
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="&nbsp;"/>
                                </f:facet>

                                <p:commandButton value="#{bundle01.ver}"  
                                                 action="#{loginUsuarioController.prepareView}" 
                                                 icon="ui-icon-extlink" ajax="false" />
                                <p:commandButton value="#{bundle01.editar}" ajax="false"   
                                                 action="#{loginUsuarioController.prepareEdit}"  
                                                 icon="ui-icon-arrowrefresh-1-w" />
                                <p:commandButton value="#{bundle01.eliminar}" icon="ui-icon-close"  
                                                 ajax="false"  action="#{loginUsuarioController.destroy}" />

                            </p:column>
                        </p:dataTable>
                    </p:panel>
                </p:outputPanel>
                <br/>
                <p:commandButton ajax="false" action="#{loginUsuarioController.prepareCreate}" value="#{bundle01.criar}"/>
            </h:form>

        </ui:define>
    </ui:composition>

</html>
